/**
 * Title: PermitController.java
 * Description: Copyright: Copyright (c) 2019 Company: BHFAE
 *
 * @author Sharp
 * @date 2019-8-2 14:54
 * @description Project Name: Grote
 * @Package: com.srct.service.account.controller
 */
package com.sharp.authorization.controller;

import com.sharp.authorization.annotation.auth.Auth;
import com.sharp.authorization.annotation.auth.LoginAuthRole;
import com.sharp.authorization.constants.token.TokenItemConst;
import com.sharp.authorization.holder.ClientTypeHolder;
import com.sharp.authorization.service.permit.PermitCoreService;
import com.sharp.authorization.service.token.TokenService;
import com.sharp.authorization.vo.permit.PermitRes;
import com.sharp.authorization.vo.permit.PermitTreeRes;
import com.sharp.kernel.config.response.Response;
import com.sharp.kernel.config.response.ResponseHandler;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@Auth(LoginAuthRole.class)
@Api(value = "权限操作", tags = "权限操作")
@RestController("PermitController")
@RequestMapping(value = "")
public class PermitController {
    @Resource
    private PermitCoreService permitCoreService;
    @Resource
    private TokenService tokenService;

    @ApiOperation(value = "权限树", notes = "登录后准入")
    @RequestMapping(value = "/permitTree", method = RequestMethod.GET)
    public ResponseEntity<Response<List<PermitTreeRes>>> getPermitTree() {
        List<PermitTreeRes> res = permitCoreService.getPermitTree();
        return ResponseHandler.generateResponse(res);
    }

    @ApiOperation(value = "权限列表", notes = "登录后准入")
    @RequestMapping(value = "/permitList", method = RequestMethod.GET)
    public ResponseEntity<Response<List<PermitRes>>> getPermitList() {
        String customerNumber = tokenService.getItem(TokenItemConst.OPERATOR.name(), String.class);
        String clientType = ClientTypeHolder.get();
        List<PermitRes> res = permitCoreService.getPermitListByCustomerNumber(customerNumber, clientType);
        return ResponseHandler.generateResponse(res);
    }

}
